<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css"/>
    <link rel="stylesheet" href="https://demo.easyweb.vip/iframe/assets/module/admin.css?v=318"/>
    <script type="text/javascript" src="/static/js/jquery-1.7.2.js"></script>
    <style>
        body .tox-tinymce-aux { z-index: 19892000; }
        .dc{ color: red; }
    </style>
</head>
<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
		<form class="layui-form" style="padding: 0px 50px 0px 0px">
		<div class="layui-form-item">
			<div class="layui-row">
				<div class="layui-col-md4">
					<label class="layui-form-label">面向对象<span class="dc">*</span></label>
					<div class="layui-input-block">
						<select name="firstMenu" lay-filter="firstMenu"  lay-search  id="firstMenu">
							<option value="">请选择面向对象</option>
							<option value="2">全部</option>
							<option value="0">学生</option>
							<option value="1">教师</option>
						</select>
					</div>
				</div>
				<div class="layui-col-md8">
					<label class="layui-form-label">公告标题<span class="dc">*</span></label>
					<div class="layui-input-block">
						<input id="title" class="layui-input" type="text" autocomplete="off" placeholder="输入公告标题">
					</div>
				</div>
			</div>
		</div>
		</form>	
        <textarea id="demoEditor"></textarea>
        </div>
        <div class="layui-form-item">
           <div class="layui-input-block text-center">
               <button ew-event="closeThisTabs" type="button" class="layui-btn layui-btn-primary" id="cloneDemoEdtInsertContent">&emsp;清除&emsp;</button>
               <button class="layui-btn" lay-filter="eQuestionSubmit" lay-submit id="eQuestionSubmit">&emsp;提交&emsp;</button>
           </div>
       </div><br><br>
    </div>
</div>
<!-- js部分 -->
<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript" src="https://demo.easyweb.vip/iframe/assets/js/common.js?v=318"></script>
<script type="text/javascript" src="https://demo.easyweb.vip/iframe/assets/libs/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
$(top.hangge());
</script>
<script>
    layui.use(['layer', 'admin', 'form', 'table','element'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var admin = layui.admin;
        var table = layui.table;
  	  	var form = layui.form;
  	  	var element = layui.element;
        var content = [
            '<div style="text-align: center;color: #fff;background-image: linear-gradient(to right,#009688,#5fb878);padding: 20px;">',
            '   <div style="font-size: 28px;margin-bottom: 10px;">EASY WEB 后台管理模板</div>',
            '   <div style="font-size: 18px">基于Layui的一套通用型后台管理模板，拥有众多原创组件及模板页面</div>',
            '</div><br/>'
        ].join('');
        initT();
        // 渲染富文本编辑器
        function initT(){
	        tinymce.init({
	            selector: '#demoEditor',
	            height: 630,
	            branding: false,
	            language: 'zh_CN',
	            plugins: 'code print preview fullscreen paste searchreplace save autosave link autolink image imagetools media table codesample lists advlist hr charmap emoticons anchor directionality pagebreak quickbars nonbreaking visualblocks visualchars wordcount',
	            toolbar: 'fullscreen preview code | undo redo | forecolor backcolor | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | formatselect fontselect fontsizeselect | link image media emoticons charmap anchor pagebreak codesample | ltr rtl',
	            toolbar_drawer: 'sliding',
	            images_upload_url: '../../../json/tinymce-upload-ok.json',
	            file_picker_types: 'media',
	            file_picker_callback: function (callback, value, meta) {
	                layer.msg('演示环境不允许上传', {anim: 6});
	            },
	            init_instance_callback: function (editor) {
	                console.log(editor);
	            }
	        });
        }
        $('#eQuestionSubmit').click(function () {
        	let audiences = $("#firstMenu").val()+'';
          	if(audiences===''){
          		layer.msg("请选择面向对象！", {icon: 5});
       		return false;
          	}
          	let title = $("#title").val()+'';
          	if($.trim(title)===''){
          		layer.msg("请输入标题！", {icon: 5});
        		return false;
          	}
	       	 // 获取内容
	         var content = tinymce.get('demoEditor').getContent()+'';
	       	 if(content===''){
	       		layer.msg("请输入内容！", {icon: 5});
	    		return false;
	       	 }
	         let params = {};
	         params.message = content;
	         params.title = title;
	         params.audiences = audiences;
	         $.ajax( {
	             url : '/admin/announcement/add', 
	             type : 'post',
	             data: params,
	             dataType : 'json',
	             success : function(data) {
	            	 if(data.code==0){
	            		 layer.msg(data.msg,{icon: 1});
	            		 $("#title").html("");
	            		 var firstMenu= document.getElementById("firstMenu");
	            		 firstMenu.innerHTML = "";
	            		 tinymce.get('demoEditor').setContent('', {});
	                     tinymce.get('demoEditor').remove();
	                     initT();
		        	 }else{
		        		 layer.msg(data.msg,{icon: 2});
		        	 }
	             }
	         });
	    });
        $('#cloneDemoEdtInsertContent').click(function () {
        	$("#title").html("");
	   		var firstMenu= document.getElementById("firstMenu");
	   		firstMenu.innerHTML = "";
	   		tinymce.get('demoEditor').setContent('', {});
            tinymce.get('demoEditor').remove();
            initT();
        });

    });
</script>
</body>
</html>